<!-- 吸顶 -->
<template>
    <div class="topheader" :class="{show:top>80}">
        <div class="container" v-show="top>80">
            <RouterLink class="logo" to="/" />
            <CommonHeader />
            <div class="right">
                <RouterLink to="/" >品牌</RouterLink>
                <RouterLink to="/" >专题</RouterLink>
            </div>
        </div>
    </div>
</template>
<script>
import CommonHeader from "./CommonHeader"
import {throttle} from "@/utils/constfun"
import _ from 'lodash'
export default {
    components:{CommonHeader},
    data(){
        return{
            top:0,//记录滚动的高度
        }
    },
    mounted() {
        //监听滚动条的高度  滚动高度大于80的时候需要做逻辑处理 没有节流的实现
        //window.addEventListener("scroll",this.setTop)
        //传统节流的实现
        // window.addEventListener("scroll",throttle(this.setTop))
        // 插件的节流实现
        window.addEventListener('scroll',_.throttle(this.setTop),200)
    },
    methods:{
        setTop(){
            this.top=document.documentElement.scrollTop
            // console.log(this.top)
        }
    },
    //组件销毁的时候清除监听的事件
    beforeDestroy() {
        window.removeEventListener("scroll",throttle(this.setTop))
    },
}
</script>
<style scoped lang='scss'>
@import "../../assets/css/variables.scss";
.topheader {
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
  .container {
    display: flex;
    align-items: center;
  }
  .logo {
    width: 200px;
    height: 80px;
    background: url(../../assets/logo.0940ebb5.png) no-repeat  right 2px;
    background-size: 160px auto;
  }
  .right {
    width: 220px;
    display: flex;
    text-align: center;
    padding-left: 40px;
    border-left: 2px solid $xtxColor;
    a {
      width: 38px;
      margin-right: 40px;
      font-size: 16px;
      line-height: 1;
      &:hover {
        color: $xtxColor;
      }
    }
  }
   transform: translateY(-100%);
   opacity: 0;
    &.show {
    transition: all 0.3s linear;
    transform: none;
     opacity: 1;
    }
}
</style>
